#include <iostream>
using namespace std;
#define gua(i,a,b) for(int i=(a);i<=(b);++i)
#define qia(i,a,b) for(int i=(a);i>=(b);--i)
int mp[1005][1005],n,ans[1005][1005];
int main(){
	cin>>n;
	gua(i,1,n)gua(j,1,i)cin>>mp[i][j];
	qia(i,n,1)gua(j,1,i)ans[i][j]=mp[i][j]+max(ans[i+1][j],ans[i+1][j+1]);
	cout<<ans[1][1]<<endl;
	return 0;
}
